import threading
import time
from PIL import ImageGrab
from function import tessreact,translate,chose,gettitle
from pywinauto import Desktop

gettitle.getTitle()
yourwin=input()

desktop = Desktop(backend="win32") # 获取桌面对象
window = desktop.window(title=yourwin) # 获取窗口对象
window.set_focus() # 将窗口置于顶层

imageorigin = ImageGrab.grab()
crop_area = chose.chose(imageorigin)

def screenshot():
    # 截取屏幕并保存到pic文件夹
    image = ImageGrab.grab()
    cropped_image = image.crop(crop_area)
    cropped_image.save(str(time.time())+'.png')
    src=tessreact.tessreact(cropped_image)
    dest=translate.translate(src)
    print(dest)
    # 重复调用自己，实现每隔一秒截屏一次
    timer = threading.Timer(1, screenshot)
    timer.start()

# 启动截屏程序
screenshot()